package edu.gatech.cs2340.bytebankers.tests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import edu.gatech.cs2340.bytebankers.model.RiverCrossing;


public class RiverCrossingTest {

	@Test
	public void testRiverDepth() {
		// This test ensures that the river depth generated is between
		// the min and max assigned through setDepthRange
		// over a large amount of tries
		RiverCrossing rCrossing = 
			new RiverCrossing("The river", null, false, true, 130, 0, 0);
		rCrossing.setDepthRange(5, 10);
		
		for(int i = 0; i < 5000; i++) {
			rCrossing.generateDepth();	
			assertTrue(rCrossing.getDepth() >= 5 && rCrossing.getDepth() <= 10);
		}	
	}
	
	@Test
	public void testRiverCrossFerry() {
		// This test ensures that a ferry crossing is always successful
		RiverCrossing rCrossing = 
			new RiverCrossing("The river", null, false, true, 130, 0, 0);
		
		boolean crossFailed = false;
		boolean crossSucceeded = false;
		
		// Create counters and increment them for each success or failure
		int successCount = 0;
		int failCount = 0;
		
		for(int i = 0; i < 100; i++) {
			rCrossing.generateDepth();	
			boolean crossed = rCrossing.crossWasSuccessful(1);
			if(crossed) {
				successCount++;
			} else {
				failCount++;
			}
			
		}
		
		// assert that the crossing never failed in any of the tests, 
		// but succeeded in all of them
		assertTrue(failCount == 0 && successCount == 100);

	}
	
	@Test
	public void testRiverCrossFord() {
		// This test ensures that when fording the river multiple times,
		// sometimes the cross will fail and sometimes it will succeed
		RiverCrossing rCrossing = 
			new RiverCrossing("The river", null, false, true, 130, 0, 0);
		
		boolean crossFailed = false;
		boolean crossSucceeded = false;
		
		for(int i = 0; i < 100; i++) {
			rCrossing.generateDepth();	
			boolean crossed = rCrossing.crossWasSuccessful(2);
			if(crossed) {
				crossSucceeded = true;
			} else { 
				crossFailed = true;
			}
		}
		
		assertTrue(crossFailed && crossSucceeded);
		
	}
	
	@Test
	public void testRiverCrossCaulk() {
		// This test ensures that when caulking the wagon multiple times,
		// sometimes the cross will fail and sometimes it will succeed
		
		RiverCrossing rCrossing = new RiverCrossing("The river", null, false, true, 130, 0, 0);
		
		boolean crossFailed = false;
		boolean crossSucceeded = false;
		
		for(int i = 0; i < 100; i++) {
			rCrossing.generateDepth();	
			boolean crossed = rCrossing.crossWasSuccessful(3);
			if(crossed) {
				crossSucceeded = true;
			} else {
				crossFailed = true;
			}
		}
		
		assertTrue(crossFailed && crossSucceeded);
		
	}
	
	
}
